home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: "John P. Atkinson" <jatk@ix.netcom.com>
- Newsgroups: comp.lang.c++
- Subject: Re: const member functions
- Date: Fri, 05 Apr 1996 14:09:06 -0800
- Organization: Data/Ware Development, Inc.
- Message-ID: <31659A02.7A9F@ix.netcom.com>
- References: <316588E6.7D61@geoplex.com>
- NNTP-Posting-Host: sdx-ca8-02.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Fri Apr 05 2:09:34 PM PST 1996
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- Jay B. Perry wrote:
- >
- > The attached code doesn't compile, complaining about the non-const
- > object's attempt to use a non-const private method (even though a
- > const public method with the same name is available).
- >
- > private: // Private methods
- > // Private accessor, should only be available to
- > // non-const X objects
- > int& value( ) { return _value; }
-
-
- OK, looks like value is a private method only. It's in scope only from within other methods of the
- X class, or from any of X's friends (you've declared none, though.)
-
-
- > // The following line results in an error for several
- > // compilers, all complaining about an attempt to use
- > // the private X::value method!
- > cout << t1.value() << endl;
-
- So, you're calling value() from within main(). main() doesn't have scope to see into the private
- portions of X. value() shouldn't be callable from main(), irrespective of const vs non-const.
-
- (I think!)
-
- --
- --John Atkinson Data/Ware Development, Inc.
- 9449 Carroll Park Drive
- jatk@ix.netcom.com San Diego, CA USA 92121 (619) 453-7660 ext.317
- "There is more to life than increasing its speed."
- --Mahatma Gandhi
-